/// 类型体系
abstract class Type{
  String name;
  Type(this.name);

  static isSimpleType(Type t){
    return t is SimpleType;
  }
  static isFunctionType(Type t){
    return t is FunctionType;
  }
  /// visitor模式
  /// 可以用于生成字节码等。
   Object accept(TypeVisitor visitor);
}

class SimpleType extends Type{
  SimpleType(String name) : super(name);
  @override
  String toString(){
    return "SimpleType {name: " + name +  "}";
  }

  @override
  Object accept(TypeVisitor visitor) {
    return visitor.visitSimpleType(this);
  }
}

class FunctionType extends Type{
  FunctionType() : super("@function");

  @override
  String toString(){
    return "FunctionType {name: " + name +  "}";
  }

  @override
  Object accept(TypeVisitor visitor) {
    return visitor.visitFunctionType(this);

  }
}

/// visitor
abstract class TypeVisitor{
  Object visit(Type t) {
      return t.accept(this);
  }
  Object visitSimpleType(SimpleType t);
  Object visitFunctionType(FunctionType t);
}